package com.inspur_video.inspur_video.service;

import com.aliyuncs.vod.model.v20170321.GetVideoListResponse;
import com.inspur_video.inspur_video.bean.tofront.SwiperImgInfo;
import com.inspur_video.inspur_video.bean.video.VideoList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @author 小浩
 * @date 2018-08-02 19:33
 * @package com.inspur_video.inspur_video.service
 * @description
 */
@Service
public class SwiperImgService {
    @Autowired
    VideoService videoService;

    public List<SwiperImgInfo> getSwiperImgInfo() {
        List<SwiperImgInfo> list = new LinkedList<>();
        // 从阿里云OSS中获取所有video信息
        VideoList videoList = videoService.getAllVideo("Normal");
        List<GetVideoListResponse.Video> videos = videoList.getVideoList();
        for (GetVideoListResponse.Video video : videos) {
            // 从阿里云bean中取出对应的值，并封装成前端所需的bean形式
            String coverURL = video.getCoverURL();
            String title = video.getTitle();
            // 赋值前先判空
            if (coverURL != null && !(coverURL.isEmpty())) {
                SwiperImgInfo swiperImgInfo = new SwiperImgInfo(coverURL, title);
                list.add(swiperImgInfo);
            }
            // 判断容量，不让前端的轮播图元素过多
            if (list.size() == 5) {
                break;
            }
        }
        return list;
    }
}
